<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/include/header.jsp"%>
<style type="text/css">
.date_txt,.input_txt{
	width: 190px;
}
.selec{
		width: 195.5px;
}
</style>
</head>
<body style="background-color: white;">
      <div class="dialog_main" style="padding: 10px;">
		<div class="b_box ch_panel" style="padding: 10px;text-align: center;">
			<form id="dickmForm">
				<input type="hidden" id="CSRFToken" name="CSRFToken" value="${csrfToken}" />
				<table class="c_table m_t10">
					<tr>
						<td class="t_r">科&nbsp;&nbsp;目&nbsp;&nbsp;分&nbsp;&nbsp;类：</td>
						<td>
							<select class="input_txt" id="leiBie" name="leiBie" data-validaterole="leiBie">
								<c:forEach items="${GET_KMFL_MAP }" var="dic">
									<option value="${dic.key }" <c:if test="${parentDickm.leiBie eq dic.key or currKeMuFenLei eq dic.key}">selected="selected"</c:if>>${dic.value }</option>
								</c:forEach>
							</select>
						</td>
						<td class="t_r">科&nbsp;&nbsp;目&nbsp;&nbsp;类&nbsp;&nbsp;别：</td>
						<td>
							<input type="hidden" id="kmLbName" name="kmLbName" value="" />
							<select class="input_txt" dicname="kmLbName" id="kmLbCode" name="kmLbCode" data-validaterole="kmLbCode">
							</select>
						</td>
					</tr>
					<tr>
						<td class="t_r">余&nbsp;&nbsp;额&nbsp;&nbsp;方&nbsp;&nbsp;向 ：</td>
						<td colspan="3">
							借&nbsp;<input type="radio" <c:if test="${parentDickm.yueFx eq '1' }">checked="checked"</c:if> class="yueFx" name="yueFx" data-validaterole="yueFx" value="1" />
							贷&nbsp;<input type="radio" <c:if test="${parentDickm.yueFx eq '-1' }">checked="checked"</c:if> class="yueFx" name="yueFx" data-validaterole="yueFx" value="-1" />
						</td>
					</tr>
					<tr>
						<td class="t_r">科目类别编码：</td>
						<td><input type="text" class="input_txt" id="dicCode" name="dicCode" data-validaterole="dicCode" value="" /></td>
						<td class="t_r">父级类别编码：</td>
						<td>
							<input type="text" disabled="disabled" class="input_txt" id="parentDicCodeTemp" value="${parentDickm.dicCode }"/>
							<input type="hidden" id="parentDicCode" name="parentDicCode" value="${parentDickm.dicCode }" />
						</td>
					</tr>
					<tr>
						<td class="t_r">科目类别名称：</td>
						<td><input type="text" class="input_txt" id="dicName" name="dicName" data-validaterole="dicName" value="" /></td>
						<td class="t_r">父级类别名称：</td>
						<td>
							<select class="input_txt" id="parentDicNameTemp">
								<option value="">==请选择==</option>
								<c:forEach items="${dicMap }" var="dic">
									<option value="${dic.key }" <c:if test="${parentDickm.dicCode eq dic.key }">selected="selected"</c:if>>${dic.value }</option>
								</c:forEach>
							</select>
							<input type="hidden" id="parentDicName" name="parentDicName" value="${parentDickm.dicName }" />
						</td>
					</tr>
				</table>
			</form>
		</div>
		<div class="action_box t_c m_t15">
			<input type="button" class="a_btn" id="addBtn" value="保存" />
		</div>
	</div>

	<script type="text/javascript">
	// 验证
	seajs.use(["component/validate", "component/tip"], function(validate, tip) {
		var ntip = function () {
			// 定义一个提示对象
			var t = new tip({
				content : 'hello tip', hasArrow : true, arrowOption : {
					dir : "left", position : {
						top : 8
					}
				}, con : "body", hasCloseBtn : false, position : {
					my : "center", at : "center", of : "#tipcon"
				}, css : {
					width : "20"
				}
			});
			return t;
		};

		var d = new validate({
			con: "#dickmForm",
			// 验证容器
			ntip: ntip,
			onSubmit: "#addBtn" // 提交按钮
		});

		// 设置拼装规则: 这里加上各个验证规则
		d.setValidateRule({ dicCode: ["isBlank", "checkLen"] });
		d.setValidateRule({ dicName: ["isBlank", "checkLen"] });
		d.setValidateRule({ leiBie: ["isBlank", "checkLen"] });
		d.setValidateRule({ yueFx: ["isBlank", "checkLen"] });
		d.setValidateRule({ itemCode: ["isBlank", "checkLen"] });
		// 注册保存按钮事件
		d.bind("onsubmit", function() {
			
			//填充选择的名称
			$.each($("select"), function (i, obj) {
				if ($(obj).val() == "") {
					$("#" + $(obj).attr("dicname")).val("");
				} else {
					$("#" + $(obj).attr("dicname")).val($(obj).children(":selected").text());
				}
			});
			
			if($(".yueFx:checked").val()==undefined){
				alert("请选择余额方向！");
				return;
			}
			
			var serializedForm = $("#dickmForm").serialize();
			$.post("${ctx}/dickm/add", serializedForm, function(result){
				if ("succ" == result) {
					alert("操作成功");
					parent.replaceByUrl('${ctx}/dickm/list');
					parent.layerClose(window.name);
				} else {
					alert(result);
				}
			});
				
		});
	});
	
	
	$(function(){
		$("#parentDicNameTemp").change( function() {
			$("#parentDicCodeTemp").val($("#parentDicNameTemp").val());
			$("#parentDicCode").val($("#parentDicNameTemp").val());
			
			var dic_name = $("#parentDicNameTemp option:selected").text();
			$("#parentDicName").val(dic_name);
		});
		
		$("#leiBie").change( function() {
			$("#kmLbCode").empty();
			var option = "";
			if($("#leiBie").val()=="ZC"){
				option+='<option value="101">流动资产</option>';
				option+='<option value="102">非流动资产</option>';
			}else if($("#leiBie").val()=="FZ"){
				option+='<option value="201">流动负债</option>';
				option+='<option value="202">非流动负债</option>';
			}else if($("#leiBie").val()=="QY"){
				option+='<option value="301">所有者权益</option>';
			}else if($("#leiBie").val()=="CB"){
				option+='<option value="401">成本</option>';
			}else if($("#leiBie").val()=="SY"){
				option+='<option value="501">营业收入</option>';
				option+='<option value="502">其他收益</option>';
				option+='<option value="503">期间费用</option>';
				option+='<option value="504">其他损失</option>';
				option+='<option value="505">营业成本及税金</option>';
				option+='<option value="506">以前年度损益调整</option>';
				option+='<option value="507">所得税</option>';
			}
			$("#kmLbCode").append(option);
			
			$.each($("#kmLbCode").find("option"), function (i, obj) {
				if ($(obj).val() == "${parentDickm.kmLbCode}") {
					$(obj).attr("selected","selected");
				}
			});
		});
		
		$("#leiBie").change();
		
		
		$(".input_txt").change( function() {
			$(this).val($.trim($(this).val()));
		});
		
	});
	
	</script>
</body>
</html>